package com.xinyue.network.codec;

/**
 * @Author 王广帅
 * @Date 2021/1/24 18:02
 */
public class GameMessageContext {
    private GameMessageHeader header;
    private IGameMessage gameMessage;

    public GameMessageContext(GameMessageHeader header) {
        this.header = header;
    }

    public void setGameMessage(IGameMessage gameMessage) {
        this.gameMessage = gameMessage;
        if (gameMessage != null) {
            GameMessageMeta gameMessageMeta = gameMessage.getClass().getAnnotation(GameMessageMeta.class);
            header.setMessageId(gameMessageMeta.messageId());
            header.setMessageType(gameMessageMeta.messageType());
        }
    }

    public GameMessageHeader getHeader() {
        return header;
    }

    public IGameMessage getGameMessage() {
        return gameMessage;
    }
}
